﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using HZ.MBSM.DBUtility;
public partial class Deparment_Filse_Files_send : System.Web.UI.Page
{
    private string _accountid = "",strShow="";
    protected void Page_Load(object sender, EventArgs e)
    {
        System.Collections.Generic.List<HZ.MBSM.DAL.AccountType> _AccountType = new System.Collections.Generic.List<HZ.MBSM.DAL.AccountType>();
        _AccountType.Add(HZ.MBSM.DAL.AccountType.enumDeparment);
        if (HZ.MBSM.BLL.Login.CheckAssert(_AccountType))
        {
            HZ.MBSM.Model.Account _Account = (HZ.MBSM.Model.Account)Session["Account"];
            _accountid = _Account.AccountId.ToString();
            if (!IsPostBack)
            {
                ShowDate();
                
            }
            if (Request.Form["delell"] == "删除")
            {
                if (Request.Form["chk"] != null)
                {
                    delell(Request.Form["chk"].ToString());
                    ShowDate();
                }
            }
        }
    }
    public void ShowDate()
    {
        Db db = new Db();
        DbPage dbPage = new DbPage(db);
        dbPage.Table = "V_D_Email";                                               //要查询的表明
        dbPage.Key = "BoxID";                                               //表的主键    
        dbPage.Where = "(DeleteFlag_from<>1 or DeleteFlag_from is null) and Accountid_From=" + _accountid;                                           //查询条件    
        dbPage.SelectField = "BoxID, EmailId,Title,convert(varchar(100),SendTime,23) as SendTime,UserName_send,case Readflag when 1 then '已读' else '未读' end Readflag,Content ";//要显示的字段
        dbPage.PageIndex = SysFun.ToInt(Request["CurrentlyPageIndex"]);          //要显示第几页   
        dbPage.PageSize = 10;                                                    //没有显示记录条数   
        dbPage.OrderBy = "BoxID ";                  //排序字段
        dbPage.OrderByIsDesc = true;
        DataTable dt = new DataTable();
        dt = dbPage.DataTable(60);
        GridView1.DataSource = dt;
        GridView1.DataBind();

        dbPage.Db.Close();
        db.Close();
        this.DbPageFlip1.DbPage = dbPage;//将数据传给控键
        GridView1.Columns[6].Visible = false;
    }

    private void delell(string id)
    {

        string dd = "update D_BoxEmail set DeleteFlag_from=1,DeleteTime_from=getdate() where BoxID in(" + id + ")";
        Db db = new Db();
        db.Command(dd);
        db.Close();
        Response.Write("<script>alert('删除成功！')</script>");
    }

    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            if (e.Row.Cells[1].Text.Length > 15)
            {
                e.Row.Cells[1].Text =  SysFun.StringInterceptFill(e.Row.Cells[1].Text, 13) + "...";
            }
            if (e.Row.Cells[2].Text.Length > 25)
            {
                strShow = SysFun.StringInterceptFill(e.Row.Cells[2].Text, 13);
                if (strShow.Contains("<") || strShow.Contains(">") || strShow.Contains("DIV"))
                    strShow = "此内容包含一些特殊样式，无法列出，请点击查看";
                e.Row.Cells[2].Text = "<a href='../ShowNote.aspx?EmailId=" + SysFun.PasswordEncrypt(e.Row.Cells[6].Text.Trim()) + "' target='_black'>" + strShow + "..." + "</a>";
            }
            else
            {
                e.Row.Cells[2].Text = "<a href='../ShowNote.aspx?EmailId=" + SysFun.PasswordEncrypt(e.Row.Cells[6].Text.Trim()) + "' target='_black'>" + e.Row.Cells[2].Text + "</a>";
            }
            
        }
    }
}
